package com.test.common;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.test.common.webserviceclient.ArrayOfString;
import com.test.common.webserviceclient.WeatherWS;
import com.test.common.webserviceclient.WeatherWSSoap;

public class WetherUtil {
	public static void main(String[] args) {
		
		// 获得中国省份、直辖市、地区和与之对应的ID
		/*ArrayOfString s = weatherWSSoap.getRegionProvince();
		List<String> list = s.getString();
		for (String string : list) {
			System.out.println(string);
			System.out.println("------------------------");
		}*/
	}
	
	public static Map<String, Object> getWether(String cityName){
		// 创建一个WeatherWS工厂
				WeatherWS factory = new WeatherWS();
				// 根据工厂创建一个WeatherWSSoap对象
				WeatherWSSoap weatherWSSoap = factory.getWeatherWSSoap();
				// 调用WebService提供的getWeather方法获取南宁市的天气预报情况
				ArrayOfString weatherInfo = weatherWSSoap.getWeather(cityName, null);
				List<String> lstWeatherInfo = weatherInfo.getString();
				// 遍历天气预报信息, 存储到map中
				Map<String, Object> maps = new LinkedHashMap<String, Object>();
				int i =0;
				for (String string : lstWeatherInfo) {
					i++;
					if(string.contains(".gif")){
						continue;
					}
					maps.put(String.valueOf(i), string);
					System.out.println(string);
					System.out.println("------------------------");
				}
				return maps;
	}
	public static String getWetherToString(String cityName){
		// 创建一个WeatherWS工厂
				WeatherWS factory = new WeatherWS();
				// 根据工厂创建一个WeatherWSSoap对象
				WeatherWSSoap weatherWSSoap = factory.getWeatherWSSoap();
				// 调用WebService提供的getWeather方法获取南宁市的天气预报情况
				ArrayOfString weatherInfo = weatherWSSoap.getWeather(cityName, null);
				List<String> lstWeatherInfo = weatherInfo.getString();
				// 遍历天气预报信息, 存储到stringbuffer
				StringBuffer buffer = new StringBuffer();
				for (String string : lstWeatherInfo) {
					if(string.contains(".gif")){
						continue;
					}
					buffer.append(string+"<br/>");
					buffer.append("----------------------------------<br/>");
					System.out.println(string);
					System.out.println("------------------------");
				}
				return buffer.toString();
	}
}
